package com.wc.alorithm_luogu.P1802;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @Author congge
 * @Date 2023/9/30 1:51
 * 5 倍经验日
 * https://www.luogu.com.cn/problem/P1802
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Input scan = new Input();
        int n = scan.nextInt();
        int medicine = scan.nextInt();
        Player[] players = new Player[n];

        for (int i = 0; i < n; i++) {
            Player player = new Player();
            players[i] = player;
            player.lose = scan.nextInt();
            player.win = scan.nextInt();
            player.needMedicine = scan.nextInt();
        }

        Comparator<Player> comparator = new Comparator<Player>() {
            @Override
            public int compare(Player o1, Player o2) {
                return o1.needMedicine - o2.needMedicine;
            }
        };
        Arrays.sort(players, comparator);
        /**
         * dp[i][j] 表示前i个用j最多获得的经验值
         */
        int[][] dp = new int[n][medicine + 1];

        /**
         * 初始化前面不够药剂时候的经验
         */
        for (int i = 0; i < players[0].needMedicine; i++) {
            dp[0][i] = players[0].lose;
        }

        /**
         * 初始化前面够药剂时候的经验
         */
        for (int i = players[0].needMedicine; i <= medicine; i++) {
            dp[0][i] = players[0].win;
        }

        /**
         * 转移方程
         */
        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= medicine; j++) {
                if (j >= players[i].needMedicine) {
                    dp[i][j] = Math.max(dp[i - 1][j] + players[i].lose,
                            dp[i - 1][j - players[i].needMedicine] + players[i].win);
                } else {
                    dp[i][j] = dp[i - 1][j] + players[i].lose;
                }
            }
        }
        /**
         * 保证所有人都能打到
         */
        int lastIndex = n - 1;
        while (lastIndex >= 0 && players[lastIndex].needMedicine > medicine) {
            dp[n - 1][medicine] += players[lastIndex].lose;
            lastIndex--;
        }
        System.out.println(dp[n - 1][medicine]*5L);
    }

    static class Player {
        public int lose;
        public int win;
        public int needMedicine;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
